package com.example.myweather.service;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.example.myweather.R;
import com.example.myweather.entity.City;
import com.example.myweather.entity.Result;

import java.net.URL;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class WeatherManager {

    public static City city;
    public City getCitynm(String cityNm) throws Exception {
        OkHttpClient okHttpClient = new OkHttpClient();
     String url= "http://api.k780.com/?app=weather.future&cityNm="+cityNm+"&appkey=60093&sign=95e2c2944c7dfc8cb7c3e3635a725707&format=json";
        Request request=new Request.Builder().url(url).build();
        Response response=okHttpClient.newCall(request).execute();
        if (response.isSuccessful()){
            String json=response.body().string();
            Log.d("test",json);
            return JSON.parseObject(json,City.class);
        }else {
            Log.d("test","连接错误");
            return  null;
        }
    }
}


